package com.pj.project4sp.drawing_model;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import com.pj.utils.sg.*;
import com.pj.utils.so.*;
import com.pj.project4sp.SP;

import com.pj.current.satoken.StpUserUtil;
import cn.dev33.satoken.annotation.SaCheckPermission;


/**
 * Controller: drawing_model -- 图纸模型管理模块表
 * @author shengzhang 
 */
@RestController
@RequestMapping("/DrawingModel/")
public class DrawingModelController {

	/** 底层 Mapper 对象 */
	@Autowired
	DrawingModelMapper drawingModelMapper;

	/** 增 */  
	@RequestMapping("add")
//	@SaCheckPermission(DrawingModel.PERMISSION_CODE)
	@Transactional(rollbackFor = Exception.class)
	public AjaxJson add(DrawingModel d){
		d.setCreateTime(new Date());
		drawingModelMapper.add(d);
		d = drawingModelMapper.getById(SP.publicMapper.getPrimarykey());
		return AjaxJson.getSuccessData(d);
	}

	/** 删 */  
	@RequestMapping("delete")
//	@SaCheckPermission(DrawingModel.PERMISSION_CODE)
	public AjaxJson delete(Long id){
		int line = drawingModelMapper.delete(id);
		return AjaxJson.getByLine(line);
	}
	
	/** 删 - 根据id列表 */  
	@RequestMapping("deleteByIds")
//	@SaCheckPermission(DrawingModel.PERMISSION_CODE)
	public AjaxJson deleteByIds(){
		List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class); 
		int line = SP.publicMapper.deleteByIds(DrawingModel.TABLE_NAME, ids);
		return AjaxJson.getByLine(line);
	}
	
	/** 改 */  
	@RequestMapping("update")
//	@SaCheckPermission(DrawingModel.PERMISSION_CODE)
	public AjaxJson update(@RequestBody  DrawingModel d){
		d.setUpdateTime(new	 Date());
		int line = drawingModelMapper.update(d);
		return AjaxJson.getByLine(line);
	}

	/** 查 - 根据id */  
	@RequestMapping("getById")
	public AjaxJson getById(Long id){
		DrawingModel d = drawingModelMapper.getById(id);
		return AjaxJson.getSuccessData(d);
	} 

	/** 查集合 - 根据条件（参数为空时代表忽略指定条件） */  
	@RequestMapping("getList")
	public AjaxJson getList() { 
		SoMap so = SoMap.getRequestSoMap();
		List<DrawingModel> list = drawingModelMapper.getList(so.startPage());
		return AjaxJson.getPageData(so.getDataCount(), list);
	}


}
